package edu.neu.agv_backend.controller;

import edu.neu.agv_backend.dto.AjaxResult;
import edu.neu.agv_backend.dto.AgvFlawDto;
import edu.neu.agv_backend.dto.TableDataInfo;
import edu.neu.agv_backend.service.FlawFromDBService;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/agv/flaw/db")
public class FlawFromDBController {

    private final FlawFromDBService flawFromDBService;

    public FlawFromDBController(FlawFromDBService flawFromDBService) {
        this.flawFromDBService = flawFromDBService;
    }

    @GetMapping("/list")
    public TableDataInfo<AgvFlawDto> listFlaw(@RequestParam(defaultValue = "1") int pageNum,
                                              @RequestParam(defaultValue = "10") int pageSize) {
        return flawFromDBService.listFlaw(pageNum, pageSize);
    }

    @GetMapping("/{id}")
    public AjaxResult<AgvFlawDto> getFlaw(@PathVariable Long id) {
        return flawFromDBService.getFlaw(id);
    }

    @PostMapping
    public AjaxResult<Void> addFlaw(@RequestBody AgvFlawDto dto) {
        return flawFromDBService.addFlaw(dto);
    }

    @PutMapping
    public AjaxResult<Void> updateFlaw(@RequestBody AgvFlawDto dto) {
        return flawFromDBService.updateFlaw(dto);
    }

    @DeleteMapping("/{id}")
    public AjaxResult<Void> delFlaw(@PathVariable Long id) {
        return flawFromDBService.delFlaw(id);
    }

    @GetMapping("/check/{taskId}")
    public AjaxResult<Void> checkAllConfirmed(@PathVariable Long taskId) {
        return flawFromDBService.checkAllConfirmed(taskId);
    }

    @GetMapping("/live/{taskId}")
    public TableDataInfo<AgvFlawDto> listByTask(@PathVariable Long taskId) {
        return flawFromDBService.listByTaskId(taskId);
    }

} 